﻿package view.mornExtends
{
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.component.*;
    import view.tips.*;

    public class FlashItem extends Box
    {
        private var _oldData:Object = null;
        private var _hasEvent:Boolean = true;
        private var _hasEff:Boolean = true;
        private var _curEff:int = 0;
        private var _myData:Object = 0;
        private var _light:XMLMovieClip;
        private var mFlagIcon:Bitmap;
        public var flagshow:Boolean = false;
        private var superbox:Container;
        public var effshow:Boolean = false;
        private var specialXml:XML;
        private var _w:int = 0;
        private var _urlimg:String = "";
        private var _curBmdUrl:String;
        private var _lightnum:int = 0;
        public static const iconXML:Class = FlashItem_iconXML;

        public function FlashItem()
        {
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this.superbox = this.getChildByName("superbox") as Container;
            if (!this.superbox)
            {
                this.superbox = new Container();
                this.superbox.name = "superbox";
                this.addChild(this.superbox);
            }
            if (this._w == 0)
            {
                this._w = this.width;
            }
            param1 = param1 == null ? ({icon:""}) : (param1);
            this._oldData = param1;
            this.setIcon();
            this.setSpecial();
            this.setTxt();
            this.setEff();
            this.setFlag();
            this.setEvent();
            this.setQianghuaLv();
            this.setShenZhuanIcon();
            return;
        }// end function

        private function setShenZhuanIcon() : void
        {
            if (!this._oldData)
            {
                return;
            }
            var _loc_1:* = this.getChildByName("sz") as Image;
            if (this._oldData.suitid > 0)
            {
                if (!_loc_1)
                {
                    if (this._oldData.suitid < 100)
                    {
                        _loc_1 = new Image("png.common.shenzhuang");
                    }
                    else
                    {
                        _loc_1 = new Image("png.common.rexie");
                    }
                    _loc_1.name = "sz";
                    _loc_1.x = 0;
                    _loc_1.y = 0;
                    this.addChild(_loc_1);
                }
                else if (this._oldData.suitid < 100)
                {
                    _loc_1.url = "png.common.shenzhuang";
                }
                else
                {
                    _loc_1.url = "png.common.rexie";
                }
            }
            else if (_loc_1)
            {
                this.removeChild(_loc_1);
                _loc_1 = null;
            }
            return;
        }// end function

        public function changeSuperLvXY(param1:int, param2:int) : void
        {
            this.superbox.x = param1;
            this.superbox.y = param2;
            return;
        }// end function

        private function setQianghuaLv() : void
        {
            var _loc_3:Label = null;
            if (!this._oldData)
            {
                return;
            }
            var _loc_1:* = this.getChildByName("icon") as Image;
            var _loc_2:* = _loc_1.width / 60;
            if (_loc_2 == 1)
            {
                this.superbox.x = 3 + 20;
            }
            else
            {
                this.superbox.x = 3;
            }
            this.superbox.y = -1;
            while (this.superbox.numChildren > 0)
            {
                
                this.superbox.removeChildAt(0);
            }
            if (this._oldData.superlevel > 0)
            {
                _loc_3 = new Label();
                _loc_3.color = MColor.New62;
                _loc_3.height = 22;
                _loc_3.width = 40;
                _loc_3.x = 0;
                _loc_3.y = -3;
                _loc_3.font = "Simsun";
                _loc_3.align = "right";
                _loc_3.stroke = "0x0";
                _loc_3.bold = true;
                if (_loc_2 == 1)
                {
                    _loc_3.size = 15;
                }
                else
                {
                    _loc_3.size = 12;
                }
                _loc_3.text = "+" + this._oldData.superlevel;
                this.superbox.addChild(_loc_3);
            }
            return;
        }// end function

        private function setSpecial() : void
        {
            var _loc_1:* = this.getChildByName("lock") as Image;
            if (this._oldData.lock)
            {
                if (!_loc_1)
                {
                    _loc_1 = new Image("png.common.lock");
                    _loc_1.name = "lock";
                    this.addChild(_loc_1);
                    _loc_1.x = this.width - _loc_1.width >> 1;
                    _loc_1.y = this.height - _loc_1.height >> 1;
                }
            }
            else if (_loc_1)
            {
                this.removeChild(_loc_1);
                _loc_1 = null;
            }
            return;
        }// end function

        public function get data() : Object
        {
            return this._oldData;
        }// end function

        private function setIcon() : void
        {
            var _loc_2:String = null;
            var _loc_1:* = this.getChildByName("icon") as Image;
            if (_loc_1)
            {
                _loc_1.url = "png.common.noramlicon";
                _loc_1.smoothing = true;
                if (this._oldData.icon != "")
                {
                    _loc_2 = "";
                    if (this._oldData.itemtype == 1000)
                    {
                        _loc_2 = UIGlobel.getItemd(3) + this._oldData.icon + ".jpg";
                    }
                    else
                    {
                        _loc_2 = UIGlobel.getItemd(1) + this._oldData.icon + Config.IconExtension;
                    }
                    _loc_2 = Config.getUrl(_loc_2, ResourceType.NORMAL);
                    App.mloader3.loadBMD(_loc_2, 1, new Handler(this.onComp, [_loc_2, _loc_1]));
                    if (this._oldData && this._oldData.gary)
                    {
                        _loc_1.filters = [this.getFilter()];
                    }
                    else
                    {
                        _loc_1.filters = null;
                    }
                    _loc_1.visible = true;
                }
                else
                {
                    _loc_1.visible = false;
                }
            }
            return;
        }// end function

        public function getFilter() : ColorMatrixFilter
        {
            var _loc_1:Array = [0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0, 0, 0, 1, 0];
            return new ColorMatrixFilter(_loc_1);
        }// end function

        private function setTxt() : void
        {
            var _loc_3:* = undefined;
            var _loc_4:* = undefined;
            var _loc_1:* = this.getChildByName("count") as Label;
            if (_loc_1)
            {
                _loc_1.width = this._w;
                _loc_1.x = 0;
                _loc_1.isHtml = true;
                _loc_1.mouseEnabled = false;
                _loc_1.mouseChildren = false;
                _loc_1.align = "right";
                _loc_1.stroke = "0x0";
                _loc_1.font = "SimSun";
                _loc_3 = this._oldData.count;
                _loc_4 = this._oldData.needCount;
                if (_loc_3 != null)
                {
                    if (_loc_4 != null)
                    {
                        if (this._oldData.needCount > this._oldData.count)
                        {
                            _loc_1.text = "<font color=\"#ff0000\">" + _loc_3 + "/" + _loc_4 + "</font>";
                        }
                        else
                        {
                            _loc_1.text = "<font color=\"#00ff00\">" + _loc_3 + "/" + _loc_4 + "</font>";
                        }
                    }
                    else if (int(_loc_3) > 1)
                    {
                        _loc_1.text = "<font color=\"#ffffff\">X" + this.getCounts(_loc_3) + "</font>";
                    }
                    else
                    {
                        _loc_1.text = "";
                    }
                }
                else
                {
                    _loc_1.text = "";
                }
            }
            var _loc_2:int = 0;
            return;
        }// end function

        private function setFlag() : void
        {
            var _loc_2:BitmapData = null;
            var _loc_3:Image = null;
            var _loc_1:* = this._oldData.flag;
            if (_loc_1 && _loc_1.length > 0 && int(_loc_1) > 0 && this.flagshow)
            {
                if (!this.mFlagIcon)
                {
                    _loc_3 = this.getChildByName("icon") as Image;
                    this.mFlagIcon = new Bitmap();
                    addChild(this.mFlagIcon);
                }
                _loc_2 = App.asset.getBitmapData("png.common.itemflag_" + _loc_1);
                if (_loc_2)
                {
                    this.mFlagIcon.bitmapData = _loc_2;
                    this.mFlagIcon.smoothing = true;
                }
                if (_loc_1 == "3")
                {
                    this.mFlagIcon.x = 0;
                    this.mFlagIcon.y = 0;
                }
                else
                {
                    this.mFlagIcon.x = this.width - 42;
                    this.mFlagIcon.y = 0;
                }
            }
            else if (this.mFlagIcon)
            {
                if (this.mFlagIcon.parent)
                {
                    this.mFlagIcon.parent.removeChild(this.mFlagIcon);
                }
                this.mFlagIcon = null;
            }
            return;
        }// end function

        private function setEff() : void
        {
            var _loc_1:String = null;
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:TipsEffect = null;
            var _loc_6:Image = null;
            var _loc_7:int = 0;
            var _loc_8:Number = NaN;
            if (this._hasEff)
            {
                if (this._light && this._light.parent)
                {
                    this.removeChild(this._light);
                    this._light.dispose();
                    this._light = null;
                }
                _loc_1 = this._oldData.light;
                if (_loc_1)
                {
                    _loc_2 = _loc_1.split("#");
                    _loc_3 = UserData.getUserData("career");
                    if (_loc_2.length == 1)
                    {
                        this.initEff2(_loc_2[0]);
                    }
                    else if (_loc_2.length == 3)
                    {
                        this.initEff2(_loc_2[(_loc_3 - 1)]);
                    }
                    else
                    {
                        this.initEff2(0);
                    }
                }
                else
                {
                    this.initEff2(0);
                }
                if (this.effshow)
                {
                    _loc_4 = this._oldData.quality;
                    if (this._curEff == _loc_4)
                    {
                        return;
                    }
                    this._curEff = _loc_4;
                    _loc_5 = this.getChildByName("effect") as TipsEffect;
                    if (_loc_5)
                    {
                        if (_loc_4 > 1)
                        {
                            _loc_5.visible = true;
                            _loc_5.show(_loc_4);
                        }
                        else
                        {
                            this.removeChild(_loc_5);
                            _loc_5.dispose();
                            _loc_5 = null;
                        }
                    }
                    else if (_loc_4 > 1)
                    {
                        _loc_5 = new TipsEffect(_loc_4);
                        _loc_5.mouseChildren = false;
                        _loc_5.mouseEnabled = false;
                        _loc_5.name = "effect";
                        _loc_5.show(_loc_4);
                        _loc_6 = this.getChildByName("icon") as Image;
                        _loc_7 = 100;
                        _loc_8 = 1;
                        if (_loc_6)
                        {
                            _loc_8 = _loc_6.width / 60;
                            _loc_5.setSize(_loc_8, (-(512 - _loc_7)) * _loc_8 / 2 - 5, (-(512 - _loc_7)) * _loc_8 / 2 - 5);
                            _loc_5.x = _loc_6.x;
                            _loc_5.y = _loc_6.y;
                        }
                        this.addChild(_loc_5);
                    }
                }
            }
            return;
        }// end function

        private function initEff2(param1:int) : void
        {
            var _loc_2:String = null;
            this._lightnum = param1;
            if (param1 > 0)
            {
                _loc_2 = "assets/images/iconeffect/light" + param1 + ".swf";
                App.mloader3.loadSWF(Config.getUrl(_loc_2), 1, new Handler(this.onComplight, [param1]));
            }
            return;
        }// end function

        private function onComplight(param1:int, param2:Object) : void
        {
            if (this._lightnum <= 0)
            {
                return;
            }
            var _loc_3:* = new XML(new EffItem.lightXmlDic[param1]);
            this._curBmdUrl = "light" + param1;
            this._light = new XMLMovieClip(this._curBmdUrl, _loc_3);
            if (param1 == 10)
            {
                this._light.scale = 0.6;
                this._light.interval = 1000 / 8;
                this._light.x = 0;
                this._light.y = 0;
            }
            else if (param1 == 11)
            {
                this._light.scale = 0.6;
                this._light.interval = 1000 / 6;
                this._light.x = (this.width - 48) / 2;
                this._light.y = (this.width - 48) / 2;
            }
            else
            {
                this._light.scale = 0.6;
                this._light.interval = 1000 / 5;
                this._light.x = (this.width - 48) / 2;
                this._light.y = (this.width - 48) / 2;
            }
            this._light.play();
            this._light.blendMode = BlendMode.ADD;
            this._light.mouseChildren = false;
            this._light.mouseEnabled = false;
            this.addChild(this._light);
            return;
        }// end function

        public function setEvent() : void
        {
            this.mouseEnabled = false;
            var _loc_1:* = this.getChildByName("icon") as Image;
            if (this._hasEvent)
            {
                if (!_loc_1.hasEventListener(MouseEvent.MOUSE_OVER))
                {
                    _loc_1.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
                }
            }
            else if (_loc_1.hasEventListener(MouseEvent.MOUSE_OVER))
            {
                _loc_1.removeEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            }
            return;
        }// end function

        protected function onOver(event:MouseEvent) : void
        {
            if (!this._oldData)
            {
                return;
            }
            var _loc_2:* = this.getChildByName("icon") as Image;
            _loc_2.removeEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            if (this._oldData.tips)
            {
                ModelProxy.change("tips", "normal", this._oldData.tipsMsg);
            }
            else if (this._oldData.itemtype == 1)
            {
                ModelProxy.change("tips", "arm", {data:this._oldData, p:new Point(GlobalLayer.instance.flashStage.mouseX, GlobalLayer.instance.flashStage.mouseY)});
            }
            else if (this._oldData.itemtype == 2)
            {
                ModelProxy.change("tips", "tool", {data:this._oldData, p:new Point(GlobalLayer.instance.flashStage.mouseX, GlobalLayer.instance.flashStage.mouseY)});
            }
            else if (this._oldData.itemtype == 0)
            {
                ModelProxy.change("tips", "tool", {data:this._oldData, p:new Point(GlobalLayer.instance.flashStage.mouseX, GlobalLayer.instance.flashStage.mouseY)});
            }
            else if (this._oldData.itemtype == 1000)
            {
                ModelProxy.change("tips", "skill", {data:this._oldData, p:new Point(GlobalLayer.instance.flashStage.mouseX, GlobalLayer.instance.flashStage.mouseY)});
            }
            this.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            return;
        }// end function

        protected function onOut(event:MouseEvent) : void
        {
            var _loc_2:* = this.getChildByName("icon") as Image;
            _loc_2.removeEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            ModelProxy.change("tips", "state", "close");
            this.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            return;
        }// end function

        private function getCounts(param1:int) : String
        {
            var _loc_2:* = param1 / 10000;
            return _loc_2 > 1 ? (param1 - _loc_2 * 10000 > 0 ? ((param1 / 10000).toFixed(1) + "万") : (_loc_2 + "万")) : (param1 + "");
        }// end function

        private function onComp(param1:String, param2:Image, param3:BitmapData) : void
        {
            if (param3 == null)
            {
                param2.url = "png.common.noramlicon";
            }
            else
            {
                param2.url = null;
                param2.bitmap.bitmapData = param3;
            }
            return;
        }// end function

        override public function remove() : void
        {
            this.dispose();
            super.remove();
            return;
        }// end function

        public function dispose() : void
        {
            if (this.mFlagIcon)
            {
                if (this.mFlagIcon.parent)
                {
                    this.mFlagIcon.parent.removeChild(this.mFlagIcon);
                }
                this.mFlagIcon = null;
            }
            this.removeEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            this.removeEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            return;
        }// end function

        public function get hasEvent() : Boolean
        {
            return this._hasEvent;
        }// end function

        public function set hasEvent(param1:Boolean) : void
        {
            this._hasEvent = param1;
            return;
        }// end function

        public function get hasEff() : Boolean
        {
            return this._hasEff;
        }// end function

        public function set hasEff(param1:Boolean) : void
        {
            this._hasEff = param1;
            return;
        }// end function

        override public function set dataSource(param1:Object) : void
        {
            this._myData = param1;
            return;
        }// end function

        override public function get dataSource() : Object
        {
            return this._myData;
        }// end function

    }
}
